package com.yuanda.wordhot.web.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.yuanda.wordhot.web.validator.command.LoginCommand;

/**
 * 登陆校验
 */
public class LoginValidator implements Validator {
	@Override
	public boolean supports(Class<?> aClass) {
		return LoginCommand.class.isAssignableFrom(aClass);
	}

	@Override
	public void validate(Object o, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email",
				"error.email.empty", "请输入Email.");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password",
				"error.password.empty", "请输入密码.");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "random",
				"error.random.empty", "请输入验证码.");
	}
}
